package com.wanma;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class Test02 {

	    public boolean isUnivalTree(TreeNode root) {
	        //遍历
	        int x  = root.val;
	        return preOrder(root,x);
	    }
	    public static boolean preOrder(TreeNode current,int x){
//	    if(current != null){
//	        if(current.val != x){
//	             return false;
//	            }
//	                preOrder(current.left,x);
//	             preOrder(current.right,x);
//	       return true;
//	    }
//		return false;
		while (current != null) {
			if(current.val != x){
	             return false;
	            }
	             preOrder(current.left,x);
	             preOrder(current.right,x);
	      
			
		}
		 return true;
	}
	    /**
	     * 判断单值树
	     * @param root
	     * @param val
	     * @return
	     */
	    public boolean isUnival(TreeNode root, int val){
	        if(root == null) return true;
	        if(root.val != val) return false;
	        
	        return isUnival(root.left, val) && isUnival(root.right, val);
	    }
	    
	    
	    public  static int[] numsSameConsecDiff(int N, int K) {
	    	if(N == 1){				//N为1，直接返回答案
				int[] res = {0,1,2,3,4,5,6,7,8,9};
				return res;
			}
	    	//第一步 确定数字范围
	    	int min=(int) Math.pow(10, (N-1));
	    	int max=(int) Math.pow(10, N);
	    	List<Object> list = new ArrayList<Object>();
	    	for(int i = min; i<max; i++){
	    		int[] x = new int[N];
	    		int j = 0;
	    		int num = i;
	    		while (i > 0) {
					x[j] = i % 10;
					j++;
					i = i / 10;
				}
	    		if(isK(x,K)) {
	    			list.add(num);	    			
	    			}
	    		x = null;
	    		i=num;
	    	}
	    	int[] nums = new int[list.size()];
	    	for(int i = 0 ; i<list.size();i++){
	    		nums[i] = (int) list.get(i);
	    		System.out.println(list.get(i));
	    	}
	    	//第二步 个位数对比
			return nums;     
	    }
	    
	    public static boolean isK(int[] n,int k){
	    	for (int i = 0; i < n.length; i++) {
	    		if(i+1 < n.length && Math.abs(n[i] - n[i+1]) != k){
	    			return false;
	    		}
			}
			return true;
	    }
	    public static void main(String[] args) {
	    	// numsSameConsecDiff(7,1);
	    	//System.out.println(Integer.parseInt("1232"));
	    	//System.out.println(Arrays.asList(new Integer[]{101647,101648,101649,101659,101673,101674}).contains(101674));
	    	String tag = "SP050";
	    	System.out.println(tag.substring(2));
	    	System.out.println(Integer.valueOf(tag.substring(2)));
	    
	    }
	    
	
}
 class TreeNode {
     int val;
     TreeNode left;
     TreeNode right;
     TreeNode(int x) { val = x; }
 }
